home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / ZIST.CPP < prev    next >
C/C++ Source or Header  |  1993-08-09  |  8KB  |  284 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    zn.cpp
  5. //   Title:    Zinc Window Template
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class ZI_ST.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <zi.hpp>
  41. #define USE_WIN_ST
  42. #if OS_DOS
  43. #include <zid.hpp>
  44. #elif OS_WINDOWS
  45. #include <ziw.hpp>
  46. #else
  47. #include <zio.hpp>
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //   Description:    Default constructor
  53. //    Parameters:
  54. //       Returns:    
  55. //----------------------------------------------------------------------------
  56. FN_M ZI_ST::ZI_ST(Z4_STATE _state)
  57. : ZN_WINDOW("WIN_ST", ZN_LOAD_CENTER|ZN_LOAD_HELPBAR|ZN_LOAD_NO_SHOW)
  58. {
  59.     ZI_ST::Initialize(CL_INIT_CLASS);
  60.     state = _state;
  61.     Setup();
  62. }
  63.  
  64.  
  65. //----------------------------------------------------------------------------
  66. //   Description:    Destructor
  67. //    Parameters:
  68. //       Returns:    
  69. //----------------------------------------------------------------------------
  70. FN_M ZI_ST::~ZI_ST()
  71. {
  72.     ZI_ST::Destroy(FALSE);
  73.     Terminate();
  74. }
  75.  
  76.  
  77. //----------------------------------------------------------------------------
  78. //   Description:    This function attempts to make a partial match to a state
  79. //                          name and place the virtual list selector on that state.
  80. //    Parameters:
  81. //       Returns:    TRUE if successful.
  82. //----------------------------------------------------------------------------
  83. VOID FN_M ZI_ST::CheckMatch()
  84. {
  85.     PCSZ pcsz = GetString(FID(STR_SEARCH));
  86.     if (pcsz && fInit)
  87.         {
  88.         CHAR szWork[160];
  89.  
  90.         strcpy(szWork, pcsz);
  91.         strtrim(szWork);
  92.         if (stricmp(szLastMatch, szWork) == 0)
  93.             return ;
  94.  
  95.         strcpy(szLastMatch, szWork);
  96.         if (st_file.First(szLastMatch) != Z4_ST_INVALID)
  97.             SetVlistPos(st_file.RecordNo());
  98.         }
  99.     return ;
  100. }
  101.  
  102.  
  103. //----------------------------------------------------------------------------
  104. //   Description:    Display detail windows
  105. //    Parameters:
  106. //       Returns:    TRUE if successful.
  107. //----------------------------------------------------------------------------
  108. BOOL FN_M ZI_ST::Detail()
  109. {
  110.     st_file.Record(lCurrent);
  111.     PZI_ST_DETAIL pzi_st_detail = new ZI_ST_DETAIL(st_file.Code());
  112.     if (pzi_st_detail == NULL)
  113.         return ErrorNoMem();
  114.     else if (pzi_st_detail->IsValid())
  115.         pzi_st_detail->Show();
  116.     return TRUE;
  117. }
  118.  
  119.  
  120. //----------------------------------------------------------------------------
  121. //   Description:    Destroy object. Free any resources used by object.
  122. //                          Normally called by destructor.
  123. //                        Should allow multiple calls from various classes.
  124. //                        A class should almost always re-init its variables when
  125. //                        it is destroyed to prevent accidents.
  126. //    Parameters:    fDestroyAll        Destroy parents also?
  127. //                                            Default is TRUE.
  128. //       Returns:    TRUE if successful.
  129. //----------------------------------------------------------------------------
  130. BOOL FN_M ZI_ST::Destroy(BOOL fDestroyAll)
  131. {
  132.     ZI_ST::Initialize(CL_INIT_CLASS_VARS);
  133.     if (fDestroyAll)                            // Destroy parent.
  134.         ZI_ST_PARENT::Destroy(fDestroyAll);
  135.     return TRUE;
  136. }
  137.  
  138.  
  139. //----------------------------------------------------------------------------
  140. //   Description:    Initialize object. 
  141. //                          Normally called by constructor.
  142. //                        Should allow multiple calls from various classes.
  143. //    Parameters:    sInit        Initialization code. May be one of the following:
  144. //                                        CL_INIT_CLASS            Reset class variables and
  145. //                                                                    and dynamic allocations for
  146. //                                                                    this class only.
  147. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  148. //                                                                    this class only.
  149. //                                        CL_INIT_VARS            Reset class variables for
  150. //                                                                    this class only.
  151. //                                        CL_INIT_ALL                Initialize class and all 
  152. //                                                                    parent class, including
  153. //                                                                    dynamic memory allocation.
  154. //                                    Default is CL_INIT_ALL
  155. //       Returns:    TRUE if successful.
  156. //----------------------------------------------------------------------------
  157. BOOL FN_M ZI_ST::Initialize(SHORT sInit)
  158. {
  159.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  160.         ZI_ST_PARENT::Initialize(sInit);
  161.  
  162.     szLastMatch[0] = '\0';
  163.     lCurrent = 0;
  164.     fInit = FALSE;
  165.     st_file.SetMask(Z4_ST_SPELLED_OUT);
  166.     lRecords = 0;
  167.     state = Z4_ST_INVALID;
  168.     return TRUE;
  169. }
  170.  
  171.  
  172. //----------------------------------------------------------------------------
  173. //   Description:    Event monitor function.
  174. //    Parameters:    msg        Event code
  175. //                        pv1            Data pointer 1
  176. //                        pv2            Data pointer 2
  177. //       Returns:    Event code
  178. //----------------------------------------------------------------------------
  179. ZN_MSG FN_M ZI_ST::User(ZN_MSG msg, PVOID, PVOID pv2)
  180. {
  181.     switch (msg)
  182.         {
  183.         case ZN_MSG_INIT:
  184.             fInit = TRUE;
  185.             if (state != Z4_ST_INVALID)
  186.                 {
  187.                 SetString(FID(STR_SEARCH), st_file.Full(state));
  188.                 CheckMatch();
  189.                 }
  190.             SetCurrent(FID(STR_SEARCH));
  191.             return msg;
  192.  
  193.         case ZN_MSG_TERMINATE:
  194.             return msg;
  195.  
  196.         case ZN_MSG_VLIST_INIT:
  197.             {
  198. static int aiTabstops[] = { 2, 45, 0, 0 };
  199.             PZN_VLIST_INIT pzn_vlist_init = (PZN_VLIST_INIT)pv2;
  200.             pzn_vlist_init->lElems = lRecords = (LONG)st_file.Records();
  201.             pzn_vlist_init->fs = ZN_VLIST_SINGLE|ZN_VLIST_TITLE;
  202.             pzn_vlist_init->aiTabstops = aiTabstops;
  203.             }
  204.             return msg;
  205.  
  206.         case ZN_MSG_VLIST_TITLE:
  207.             {
  208.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  209.             pzn_vlist_elem->pszBuf = szFormat;
  210.             strcpy(szFormat, "\tState\tAbbreviation");
  211.             }
  212.             return msg;
  213.         }
  214.     if (IsError())                                // Error condition
  215.         return msg;
  216.     switch (msg)
  217.         {
  218.         case ZN_MSG_STRING_CHANGE:
  219.             CheckMatch();
  220.             break;
  221.  
  222.         case ZN_MSG_VLIST_QUERY:
  223.             {
  224.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  225.             pzn_vlist_elem->pszBuf = szFormat;
  226.             szFormat[0] = '\0';
  227.             if (st_file.Record(pzn_vlist_elem->lId))
  228.                 sprintf(szFormat, "\t%s\t%s", (PSZ)st_file, st_file.Abbreviation());
  229.             }
  230.             break;
  231.  
  232.         case ZN_MSG_VLIST_SELECT:
  233.             {
  234.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  235.             lCurrent = pzn_vlist_elem->lId;
  236.             }
  237.             // Fall through
  238.         case ZN_MSG_VLIST_CURRENT:
  239.             {
  240.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  241.             LONG lRec = pzn_vlist_elem->lId;
  242.             st_file.Record(lCurrent);
  243.             sprintf(szFormat, "State %lu of %lu, %s",
  244.                 (LONG)lRec+1, (LONG)st_file.Records(),
  245.                 st_file.Abbreviation());
  246.             SetHelp(szFormat);
  247.             }
  248.             break;
  249.  
  250.         case ZN_MSG_VLIST_DBL_CLK:
  251.             {
  252.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  253.             lCurrent = pzn_vlist_elem->lId;
  254.             }
  255.             // Fall through
  256.         case TB_DETAIL:
  257.             Detail();
  258.             break;
  259.  
  260.         case ZN_MSG_HELP:
  261.             return ZN_MSG_NO_HELP;
  262.  
  263.         case TB_CLOSE:
  264.             Close();
  265.             break;
  266.  
  267.         case TB_SELECT:
  268.             st_file.Record(lCurrent);
  269.             SendMessage(ZiMainWindow(), ZI_MSG_STATE, NULL, (PVOID)st_file.Abbreviation());
  270.             SendMessage(ZiMainWindow(), ZI_MSG_CITY, NULL, NULL);
  271.             SendMessage(ZiMainWindow(), ZI_MSG_ZIP5, NULL, NULL);
  272.             Close();
  273.             break;
  274.  
  275.         case TB_HELP:
  276.             NotDone();
  277.             break;
  278.         }
  279.     return msg;
  280. }
  281. //----------------------------------------------------------------------------
  282. //------------------------------- End of File --------------------------------
  283. //----------------------------------------------------------------------------
  284.